package no.ntnu.idi.deid.config;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/*
 * Denne klassen består av kun statiske variabler. Den henter ut info fra konfigurasjonsfila. Alle getterne henter ut ved hjelp av den
 * private readFile hjelpemetoden.
 */

public class FilePaths {
	public static final String CONFIG_PATH = "configuration/config.cfg"; //konstant som peker til hvor konfigurasjonsfila eksisterer.

	//Konstanter som inneholder Stringen som står før en instilling i konfigfila. Brukes til å kjenne igjen hvilken linje instillingen
	//står på.
	private static final String TERM_INDEX_DIRECTORY = "TERM_INDEX_DIRECTORY";
	private static final String TERM_DICTIONARY_DIRECTORY = "TERM_DICTIONARY_DIRECTORY";
	private static final String REGEX_DATABASE_PATH = "REGEX_DATABASE_PATH";
	
	private static final String MEDICAL_KEYWORDS_PATH = "MEDICAL_KEYWORDS_PATH";
	private static final String ZIP_CODES_PATH  = "ZIP_CODES";
//	private static final String LEGEMIDLER_PATH  = "LEGEMIDLER";
	private static final String SNOMED_PATH  = "SNOMED";
	private static final String NORKOMPLEKS_PATH  = "NORKOMPLEKS";
	private static final String NCSP_PATH  = "NCSP";
	private static final String ICPC2_PATH  = "ICSP";
	private static final String ICD10_OWL_PATH  = "ICD10";
	private static final String ATC_CODES_PATH  = "ATC";
	private static final String MESH_CODES_PATH  = "MESH";
	private static final String NCMP_CODES_PATH = "NCMP";
	private static final String NCRP_CODES_PATH = "NCRP";
	private static final String ORGANIZATION_NAMES_PATH = "RESH";
	
	
	private static final String INPUT_PATH = "INPUT_PATH";
	private static final String POS_TAGGED_FILES_PATH  = "POS_TAGGED_FILES";
	private static final String SENTENIZED_FILES_PATH  = "SENTENIZED_FILES";
	private static final String POS_TAGGER_PATH  = "POS_TAGGER";
	private static final String OUTPUT_FOLDER_PATH = "OUTPUT_FOLDER";
	private static final String WORDCOUNT_STATS_FILE = "WORDCOUNT_STATS_FILE";
	private static final String STATS_FILE = "POST_PROC_STATS_FILE";
	private static final String WASHED_FILES_FOLDER = "WASHED_FILES_FOLDER";
	private static final String SIMSTRING_QUERY_SCRIPT = "SIMSTRING_QUERY_SCRIPT";
	private static final String SIMSTRING_DATABASE_BUILDER_SCRIPT = "SIMSTRING_DATABASE_BUILDER_SCRIPT";
	private static final String DE_IDENTIFIED_FILES_FOLDER = "DE_IDENTIFIED_FILES_FOLDER";
	private static final String PHRASE_DATABASE_FOLDER = "PHRASE_DATABASE_FOLDER";
	private static final String PHRASE_TEXTFILES_FOLDER = "PHRASE_TEXTFILES_FOLDER";
	private static final String LEMMATIZED_FILES_FOLDER = "LEMMATIZED_FILES_FOLDER";
	private static final String SIMSTRING_QUERY_WINDOWS = "SIMSTRING_QUERY_WINDOWS";
	private static final String SIMSTRING_DATABASE_BUILDER_WINDOWS = "SIMSTRING_DATABASE_BUILDER_WINDOWS";
	
	private static final String SENTENCE_IDF_DATABASE = "SENTENCE_IDF_DATABASE";
	private static final String TOKEN_IDF_DATABASE = "TOKEN_IDF_DATABASE";
	
	
	
	//Privat konstruktør for å hindre at klassen kan instansieres
	private FilePaths()
	{

	}

	//Tar inn en string som sier noe om hva som er prefiksen til en instilling. Så henter den ut Stringen som ligger etter prefiksen.
	private static String readFile(String input)
	{
		try {
			Reader reader = new FileReader(CONFIG_PATH); //Henter konfigfila
			BufferedReader br = new BufferedReader(reader);
			String line = br.readLine();
			while (line!=null) {//Leser den linje for linje frem til input er funnet i configfila
				{
					String formatedLine = line;
					int equalSign = line.indexOf('=');
					if( equalSign != -1) {
						formatedLine = line.substring(0,equalSign).trim();
					}					
					if(formatedLine.equals(input))
					{
						String returnString = line.substring(input.length()); //Når ei linje er funnet, fjerner man input fra linja, siden den bare inneholder en prefiks og selve instillingen ligger etterpå.
						returnString = returnString.replace("=", "").trim(); //fjerner = og whitespace
						reader.close();
						br.close();
						return returnString; //returnerer
					}

					line = br.readLine();
				}
			}
			reader.close();
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "";
	}
			
	public static String getSentenceIDFDatabase() {
		return readFile(SENTENCE_IDF_DATABASE);
	}
	
	public static String getTokenIDFDatabase() {
		return readFile(TOKEN_IDF_DATABASE);
	}
	
	public static String getSimstringDataBaseBuilderWindows() {
		return readFile(SIMSTRING_DATABASE_BUILDER_WINDOWS);
	}
	
	public static String getSimstringQueryWindows() {
		return readFile(SIMSTRING_QUERY_WINDOWS);
	}
	
	public static String getLemmatizedDirectory() {
		return readFile(LEMMATIZED_FILES_FOLDER);
	}
	
	//detter er bare gettere for de forskjellige configlinjene, alle metodene bruker reafile-metoden.
	public static String getTermDictionaryDirectory() {
		return readFile(TERM_DICTIONARY_DIRECTORY);
	}
	
	public static String getMeshCodesPath() {
		return readFile(MESH_CODES_PATH);
	}

	public static String getNCMPCodesPath() {
		return readFile(NCMP_CODES_PATH);
	}
	
	public static String getNCRPCodesPath() {
		return readFile(NCRP_CODES_PATH);
	}
	
	public static String getOrganizationNamesPath() {
		return readFile(ORGANIZATION_NAMES_PATH);
	}
	
	public static String getNorkompleksFile() {
		return readFile(NORKOMPLEKS_PATH);
	}
	public static String getSimStringDatabaseFolder() {
		return readFile(PHRASE_DATABASE_FOLDER);
	}
	
	public static String getSimStringTextfilesFolder() {
		return readFile(PHRASE_TEXTFILES_FOLDER);
	}
	
	
	public static String getSimStringDatabaseBuilderScript() {
		return readFile(SIMSTRING_DATABASE_BUILDER_SCRIPT);
	}
	
	public static String getSimstringQueryScript() {
		return readFile(SIMSTRING_QUERY_SCRIPT);
	}
	
	public static String getWordCountStatsFilePath() {
		return readFile(WORDCOUNT_STATS_FILE);
	}
	
	public static String getStatsFilePath() {
		return readFile(STATS_FILE);
	}
	
	public static String getOutputFolderPath () {
		return readFile(OUTPUT_FOLDER_PATH);
	}
	
	public static String getICD10OwlFilePath() {
		return readFile(ICD10_OWL_PATH);
	}

	public static String getATCCodesFilePath() {
		return readFile(ATC_CODES_PATH);
	}
	
	public static String getMedicalKeywordsPath() {
		return readFile(MEDICAL_KEYWORDS_PATH);
	}

	public static String getTermIndexDirectory() {
		return readFile(TERM_INDEX_DIRECTORY);
	}

	public static String getRegexDatabaseFilePath() {
		return readFile(REGEX_DATABASE_PATH);
	}
	
	public static String getInputPath() {
		return readFile(INPUT_PATH);
	}
	
	public static String getSnomedInputPath(){
		return readFile(SNOMED_PATH);
	}
	
	public static String getZipCodesPath(){
		return readFile(ZIP_CODES_PATH);
	}
	
	public static String getDeIdentifiedFilesFolderPath(){
		return readFile(DE_IDENTIFIED_FILES_FOLDER);
	}
	
	public static String getNCSPCodesPath(){
		return readFile(NCSP_PATH);
	}
	
	public static String getICPC2CodesPath(){
		return readFile(ICPC2_PATH);
	}
	
	public static String getWashedFilesFolder(){
		return readFile(WASHED_FILES_FOLDER);
	}
	public static String getPOSTaggedFilesPath(){
		return readFile(POS_TAGGED_FILES_PATH);
	}
	
	public static String getSentenizedFilesPath(){
		return readFile(SENTENIZED_FILES_PATH);
	}
	
	public static String getPosTaggerPath(){
		return readFile(POS_TAGGER_PATH);
	}
}
